<%@page import="edu.cmu.aes.project2.SupplierService"%>
<%
	request.setAttribute("title", "Models page");
	String errorMessage = "";
	boolean isError = false;
	String brandsName = request.getParameter("brandName");
	if(brandsName == null)
		brandsName = "";
	SupplierService service = new SupplierService(); 
	String[] models = service.getModels(brandsName);
	if(models == null || models.length==0){
		errorMessage = "Models for "+ brandsName+" are not found";
		isError = true;
	}
%>

<%@include file='/WEB-INF/template/header.jsp'%>
<%@include file='/WEB-INF/template/right-menu.jsp'%>
<script type="text/javascript">
	function gotoDetail(brandName){
		$("#modelName").val(brandName);
		$("#redirect_form").submit();
	}
</script>
<form name="redirect_form" id="redirect_form" action="details.jsp" method="post">
	<input type="hidden" name="modelName" id="modelName" value="">
</form>
<div id="content">
Hello Biker!!! <br/>
<br/>
<% if(isError){ %>
	<font class='error'><%=errorMessage %></font>
<% }else{ %>
Please select models we have below <br/>
<br/>
<%
	for(String model : models){
		out.println("<a href=\"javascript:gotoDetail('"+model+"')\">");	
		out.println(model);
		out.println("</a>");
		out.println("<br/>");
	}
%>
<% } %>
</div>
<%@include file='/WEB-INF/template/footer.jsp'%>
